package com.abpa.util.unidata.impl;

import com.abpa.util.unidata.*;
import asjava.uniobjects.UniSession;
import asjava.uniobjects.UniSessionException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Matthew Sowders
 */
public class UniSessionWrapper implements Session {

    private UniSession session;
    private String user;
    private String password;
    private String account;
    private String host;

    public UniSessionWrapper() {
        session = new UniSession();
    }

    /**
     * Initialize the session by calling connect.
     */
    public void init() {
        try {
            Logger.getLogger(UniSessionWrapper.class.getName()+":"+account).log(Level.INFO, "initializing session");
            session.connect();
        } catch (UniSessionException ex) {
            Logger.getLogger(UniSessionWrapper.class.getName()+":"+account).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Clean up resources by clossing the session.
     */
    public void close() {
        try {
            Logger.getLogger(UniSessionWrapper.class.getName()+":"+account).log(Level.INFO, "closing session");
            session.disconnect();
        } catch (UniSessionException ex) {
            Logger.getLogger(UniSessionWrapper.class.getName()+":"+account).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the session
     */
    public UniSession getSession() {
        return session;
    }

    /**
     * @param session the session to set
     */
    public void setSession(UniSession session) {
        this.session = session;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
        this.session.setUserName(user);
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
        this.session.setPassword(password);
    }

    /**
     * @return the account
     */
    public String getAccount() {
        return account;
    }

    /**
     * @param account the account to set
     */
    public void setAccount(String account) {
        this.account = account;
        this.session.setAccountPath(account);
    }

    /**
     * @return the host
     */
    public String getHost() {
        return host;
    }

    /**
     * @param host the host to set
     */
    public void setHost(String host) {
        this.host = host;
        this.session.setHostName(host);
    }
}
